package com.itheima.travel.web;

import com.itheima.travel.service.CategoryService;
import com.itheima.travel.utils.BeanFactory;
import com.itheima.travel.web.base.BaseServlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/categoryServlet")
public class CategoryServlet extends BaseServlet {
    /**
     * 查询所有分类信息
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void findCategoryAll(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("application/json;charset=utf-8");
        try {
            //调用service
            CategoryService service = (CategoryService)BeanFactory.getBean("CategoryService");
            String categoryListJson = service.findCategoryAll();
            System.out.println(categoryListJson);
            //返回给浏览器展示
            response.getWriter().print(categoryListJson);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}